set(LIB_OUTPUT_NAME pmalloc)
set(LIB_STATIC_OUTPUT_NAME ${LIB_OUTPUT_NAME}_static)

set (CMAKE_POSITION_INDEPENDENT_CODE TRUE)

aux_source_directory(. DIR_LIB_SRCS)

include_directories(
    ../export_como
)

set(COMMON_C_FLAGS )

if("$ENV{VERSION}" STREQUAL "rls")
    set(CMAKE_CXX_FLAGS
        "${COMMON_C_FLAGS} -Os -fno-strict-aliasing -g" CACHE STRING "" FORCE)
else()
    set(CMAKE_CXX_FLAGS
        "${COMMON_C_FLAGS} -O0 -fno-strict-aliasing -g" CACHE STRING "" FORCE)
endif()

add_library(${LIB_OUTPUT_NAME} SHARED ${DIR_LIB_SRCS})
add_library(${LIB_STATIC_OUTPUT_NAME} STATIC ${DIR_LIB_SRCS})

set_target_properties(${LIB_OUTPUT_NAME} PROPERTIES VERSION 1.8.0 SOVERSION 1)
set_target_properties(${LIB_STATIC_OUTPUT_NAME} PROPERTIES VERSION 1.8.0 SOVERSION 1)

target_include_directories(${LIB_OUTPUT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(${LIB_STATIC_OUTPUT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

install(TARGETS ${LIB_OUTPUT_NAME} LIBRARY DESTINATION lib)
install(TARGETS ${LIB_STATIC_OUTPUT_NAME} ARCHIVE DESTINATION lib)

install(FILES pmalloc.h DESTINATION include)

